//
//  NewTaskFooterView.m
//  BaishidaiKnight
//
//  Created by mac book on 2019/1/28.
//  Copyright © 2019年 sy. All rights reserved.
//

#import "NewTaskFooterView.h"

@interface NewTaskFooterView ()

@property(nonatomic,strong) UIView* topView;
@property(nonatomic,strong) UIView* bottomView;
@property(nonatomic,strong) UIView* lineView;
@property(nonatomic,strong) UIView* bottomLineView;


@property(nonatomic,strong) UIButton * rushBtn;
@property(nonatomic,strong) UIButton * iconBtn;
@property(nonatomic,strong) UILabel * sendAddressLabel;
@property(nonatomic,strong) TTTAttributedLabel * reGeocodeLabel;
@property(nonatomic,strong) UILabel * distanceLabel;
@property(nonatomic,strong) TTTAttributedLabel* remarkLabel;

@end


@implementation NewTaskFooterView

-(instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if(self){

        [self layoutUI];
    }
    return self;
}


#pragma mark -
-(void)layoutUI{
    [self addSubview:self.topView];
    [self addSubview:self.lineView];
    [self addSubview:self.bottomView];
    [self addSubview:self.bottomLineView];

  
    [self.bottomView addSubview:self.rushBtn];
    
    
    [self.topView addSubview:self.iconBtn];
    [self.topView addSubview:self.sendAddressLabel];
    [self.topView addSubview:self.reGeocodeLabel];
    [self.topView addSubview:self.distanceLabel];
    [self.topView addSubview:self.remarkLabel];
    
    
    [self.bottomLineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(10);
        make.left.right.equalTo(self);
        make.bottom.equalTo(self);
    }];
    
    [self.bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(60);
        make.left.right.equalTo(self);
        make.bottom.equalTo(self.bottomLineView.mas_top);
    }];
    
    [self.rushBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.bottomView).offset(10);
        make.left.equalTo(self.bottomView).offset(10);
        make.right.equalTo(self.bottomView).offset(-10);
        make.bottom.equalTo(self.bottomView).offset(-10);
    }];
    
    [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.bottomView.mas_top);
        make.left.right.equalTo(self);
        make.height.mas_equalTo(0.8);
    }];
    
    [self.topView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self);
        make.left.right.equalTo(self);
        make.bottom.equalTo(self.lineView.mas_top);
    }];
    
    [self.iconBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.topView);
        make.size.mas_equalTo(CGSizeMake(25, 25));
        make.left.equalTo(self.topView).offset(10);
    }];

    [self.distanceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.topView);
        make.size.mas_equalTo(CGSizeMake(100, 30));
        make.right.equalTo(self.topView).offset(-10);
    }];



    [self.sendAddressLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.topView);
        make.left.equalTo(self.iconBtn.mas_right).offset(10);
        make.right.equalTo(self.distanceLabel.mas_left);
        make.height.equalTo(self.topView).multipliedBy(0.5);

    }];

    [self.remarkLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(20);
        make.left.equalTo(self.sendAddressLabel);
        make.right.equalTo(self.sendAddressLabel);
        make.bottom.equalTo(self.topView);

    }];

    [self.reGeocodeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.sendAddressLabel.mas_bottom);
        make.left.equalTo(self.sendAddressLabel);
        make.right.equalTo(self.sendAddressLabel);
        make.bottom.equalTo(self.remarkLabel.mas_top);

    }];
    
}


#pragma mark - 抢单
-(void)qiangdanBtnDidClicked:(UIButton*)sender{
    
    if(self.delegate && [self.delegate respondsToSelector:@selector(NewTaskFooterView:)]){
        [self.delegate NewTaskFooterView:self.taskModel];
    }
    
    
}

#pragma mark - setter
-(void)setTaskModel:(TaskModel *)taskModel{
    
    _taskModel = taskModel;
    
    self.sendAddressLabel.text = taskModel.sendaddress;
    self.reGeocodeLabel.text =  taskModel.address_road;
    [_rushBtn setTitle:@"抢单" forState:UIControlStateNormal];
    if (taskModel.order_mark.length != 0) {
        self.remarkLabel.hidden = NO;
        self.remarkLabel.text =  [NSString stringWithFormat:@"备注：%@",taskModel.order_mark];
    }else{
        self.remarkLabel.hidden = YES;
    }
    
}

#pragma mark - 懒加载
-(UIView *)topView{
    if(!_topView){
        _topView  = [[UIView alloc]init];
        _topView.backgroundColor = [UIColor whiteColor];
    }
    return _topView;
}
-(UIView *)lineView{
    if(!_lineView){
        _lineView  = [[UIView alloc]init];
        _lineView.backgroundColor =kMyColor(231, 231, 231);
    }
    return _lineView;
}
-(UIButton *)iconBtn{
    if(!_iconBtn){
        _iconBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_iconBtn setImage:[UIImage imageNamed:@"icon_sendstatus_light"] forState:UIControlStateNormal];
        _iconBtn.userInteractionEnabled = NO;
    }
    return _iconBtn;
}

-(UILabel *)sendAddressLabel{
    if(!_sendAddressLabel){
        _sendAddressLabel = [[UILabel alloc]init];
        _sendAddressLabel.font = [UIFont systemFontOfSize:14.f];
        _sendAddressLabel.lineBreakMode = NSLineBreakByCharWrapping;
        _sendAddressLabel.numberOfLines = 0;
    }
    return _sendAddressLabel;
}

-(TTTAttributedLabel *)reGeocodeLabel{
    if(!_reGeocodeLabel){
        _reGeocodeLabel = [[TTTAttributedLabel alloc]initWithFrame:CGRectZero];
        _reGeocodeLabel.textColor = [UIColor grayColor];
        _reGeocodeLabel.font = [UIFont systemFontOfSize:12.f];
        _reGeocodeLabel.lineBreakMode = NSLineBreakByCharWrapping;
        _reGeocodeLabel.numberOfLines = 0;
        _reGeocodeLabel.verticalAlignment=TTTAttributedLabelVerticalAlignmentTop;
        
    }
    return _reGeocodeLabel;
}

-(TTTAttributedLabel *)remarkLabel{
    if(!_remarkLabel){
        _remarkLabel = [[TTTAttributedLabel alloc]initWithFrame:CGRectZero];
        _remarkLabel.textColor = [UIColor grayColor];
        _remarkLabel.font = [UIFont systemFontOfSize:12.f];
        _remarkLabel.lineBreakMode = NSLineBreakByCharWrapping;
        _remarkLabel.numberOfLines = 0;
        _remarkLabel.verticalAlignment=TTTAttributedLabelVerticalAlignmentTop;
        
    }
    return _remarkLabel;
}


-(UIView *)bottomView{
    if(!_bottomView){
        _bottomView = [[UIView alloc]init];
        _bottomView.backgroundColor = [UIColor whiteColor];
    }
    return _bottomView;
}

-(UIView *)bottomLineView{
    if(!_bottomLineView){
        _bottomLineView = [[UIView alloc]init];
        _bottomLineView.backgroundColor = [UIColor groupTableViewBackgroundColor];
    }
    return _bottomLineView;
}


-(UIButton *)rushBtn{
    if(!_rushBtn){
        _rushBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _rushBtn.backgroundColor = getColor(@"27B088");
        [_rushBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        _rushBtn.layer.masksToBounds = YES;
        _rushBtn.layer.cornerRadius = 5.f;
        [_rushBtn addTarget:self action:@selector(qiangdanBtnDidClicked:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _rushBtn;
}

-(UILabel *)distanceLabel{
    if(!_distanceLabel){
        _distanceLabel = [[UILabel alloc]init];
        _distanceLabel.font = [UIFont systemFontOfSize:12.f];
        _distanceLabel.textColor =  kMyColor(113, 113, 113);
    }
    return _distanceLabel;
}



/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
